module view {
	/**
	 *
	 * @author 
	 *
	 */
    export class MainView extends eui.Component {
        buildBtn: eui.Button
        smithyBtn: eui.Button
        petHouseBtn: eui.Button
        playerInfoBtn: eui.Button
        storeBtn: eui.Button
        bagBtn: eui.Button
        arsenalBtn: eui.Button
        mapEntranceBtn: eui.Button
        developmentBtn: eui.Button
        farmLandBtn: eui.Button
        public constructor() {
            super()
            this.name = "MainView"
            this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this)
            this.skinName = "resource/skin/MainSkin.exml"
        }

        protected onComplete(): void {
            this.buildBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.build,this)
            this.smithyBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.smithy,this)
            this.petHouseBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.petHouse,this)
            this.playerInfoBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.playerInfo,this)
            this.storeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.store,this)
            this.bagBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.bag,this)
            this.arsenalBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.arsenal,this)
            this.mapEntranceBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.mapEntrance,this)
            this.developmentBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.development,this)
            this.farmLandBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.farmLand,this)
            var basicInfoView = new BasicInfoView()
            this.addChild(basicInfoView)
        }

        protected build(): void {
            var child = new view.BuildView()
            this.stage.addChild(child)
        }

        protected smithy(): void {
            var child = new view.SmithyView()
            this.stage.addChild(child)
        }

        protected petHouse(): void {
            var child = new view.PetHouseView()
            this.stage.addChild(child)
        }

        protected playerInfo(): void {
            var child = new view.PlayerInfoView()
            this.stage.addChild(child)
        }

        protected store(): void {
            var child = new view.StoreView()
            this.stage.addChild(child)
        }

        protected bag(): void {
            var child = new view.BagView()
            this.stage.addChild(child)
        }

        protected arsenal(): void {
            var child = new view.ArsenalView()
            this.stage.addChild(child)
        }

        protected mapEntrance(): void {
            var child = new view.MapEntranceView()
            this.stage.addChild(child)
        }

        private development(): void {
            var child = new view.DevelopView()
            this.stage.addChild(child)
        }

        private farmLand(): void {
            var child = new view.FarmLandView()
            this.stage.addChild(child)
        }
    }

    export class BasicInfoView extends eui.Component {
        dayLabel: eui.Label
        timeLabel: eui.Label
        seasonLabel: eui.Label
        weatherLabel: eui.Label
        public constructor() {
            super()
            this.name = "BasicInfoView"
            this.skinName = "resource/control/BasicInfoSkin.exml"
            //this.show()               
            
            //var timer = new egret.Timer(200,10000)
            //timer.addEventListener(egret.TimerEvent.TIMER,this.timerHandler,this)
            //timer.start()
            timeRunEd.addEventListener(game.TimeRunEvent.name,this.handler,this)
        }

        private timerHandler(evt: egret.TimerEvent) {
            game.playerHandle.timeRun()
        }

        private handler(evt: game.TimeRunEvent) {
            //gplayer.basicInfo.time += 1
            this.dayLabel.text = Math.floor(gplayer.basicInfo.time / 96 + 1) + '日'
            var time = Math.floor(gplayer.basicInfo.time % 96 / 4) + 1            
            var timeText = ''
            if(time >= 6 && time <= 10) {
                timeText = '早上'
            } else if(time >= 11 && time <= 13) {
                timeText = '中午'
            } else if(time >= 14 && time <= 16) {
                timeText = '下午'
            } else if(time >= 17 && time <= 19) {
                timeText = '傍晚'
            } else if(time >= 20 && time <= 23) {
                timeText = '晚上'
            } else if(time === 24 || (time >= 0 && time <= 2)) {
                timeText = '深夜'
            } else if(time >= 3 && time <= 5) {
                timeText = '凌晨'
            }
            this.timeLabel.text = timeText + ':' + time + '时'
            var season = ['春','夏','秋','冬']
            this.seasonLabel.text = season[gplayer.season]
            var weather = ['晴天','下雨','阴天','雷雨','下雪','沙暴']
            this.weatherLabel.text = weather[gplayer.weather.index]
        }
    }
}
